using System;
using System.Web;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;
using Nullables;

namespace Sedna.Core.Controls.Actions
{
	/// <summary>
	/// Summary description for ValidateExecutionContextRequiredValue.
	/// </summary>
	public class ValidateExecutionContextRequiredValue: AbstractValidationAction 
	{
		private string contextName;

		public string ContextName
		{
			set { contextName = value; }
		}

		protected override bool Validate(IExecutionContext executionContext)
		{
			object value=executionContext[contextName];

			//May be it's better to use IExpressionValueStrategy?
			if (value==null)
			{
				return false;
			}

			if (value is string && String.Empty.Equals(value))
			{
				return false;
			}

			INullableType nullable=value as INullableType; 
			if (nullable!=null && !nullable.HasValue)
			{
				return false;
			}
			return true;
		}
	}
}
